package dao.version5;


import utils.version5.ConnetionFactory;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserInfoHistoryDao {

    private ConnetionFactory factory;

    public UserInfoHistoryDao(ConnetionFactory factory) {
        this.factory = factory;
    }

    public  void insert(String userid, String username) {
        String sql = "INSERT INTO userinfohistory(userid, username) VALUES (?,?)";

        try {
            throwError();
            PreparedStatement preparedStatement = factory.getCurrentConnection().prepareStatement(sql);
            preparedStatement.setString(1,userid);
            preparedStatement.setString(2,username);
            preparedStatement.executeUpdate();
            preparedStatement.close();
        } catch (SQLException e) {
            throw new RuntimeException("insert failed in userinfohistorydao");
        }
    }
    private void throwError(){
        throw new RuntimeException("模拟出错 userinfohistorydao");
    }
}
